package org.opens.javaskill.thread.executor;

import java.util.Random;

public class Task implements Runnable {

    protected int countDown = 10;

    private static int TASK_COUNT = 0;

    private int id = TASK_COUNT++;

    @Override
    public void run() {
        Random random = new Random();
        while((countDown--) > 0) {
            System.out.println(status());
            try {
                Thread.sleep(random.nextInt(3) * 300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public String status() {
        return "#(" + id + ")-(" + (countDown == 0 ? "off" : countDown) + ")";
    }

}
